package com.github.ecbp.store.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.ecbp.common.data.entity.BaseEntity;
import com.github.ecbp.common.data.service.impl.BaseServiceImpl;
import com.github.ecbp.store.service.entity.Brand;
import com.github.ecbp.store.service.mapper.BrandMapper;
import com.github.ecbp.store.service.service.BrandService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @Author Created by Alex·He on 2020/4/3 0:03
 * @Version V1.0
 * @Description: 品牌表(Brand)表服务实现类
 */
@Service
public class BrandServiceImpl extends BaseServiceImpl<BrandMapper, Brand> implements BrandService {

    /**
     *功能描述：
     * @author Created by Alex·He on 2020/4/28 11:28
     * @version 1.0
     * @description 修改品牌显示状态
     */
    @Override
    public boolean updateShowStatus(Long id, Integer showStatus) {
        Brand brand = new Brand();
        brand.setId(id);
        brand.setShowStatus(showStatus);
        return super.updateByIdBase(brand);
    }

    /**
     *功能描述:
     * @auther: Created by Alex·He 2020/4/13 22:16
     * @description: 模糊查询的参数组合，可通过品牌名称、首字母、是否为品牌制造商、显示状态进行单独或者联合查询
     */
    @Override
    protected void assemble(Brand entity, LambdaQueryWrapper<Brand> wrapper) {
        super.assemble(entity, wrapper);
        if (!StringUtils.isEmpty(entity.getName())) {
            wrapper.likeRight(Brand::getName, entity.getName());
        }
        if (!StringUtils.isEmpty(entity.getFirstLetter())) {
            wrapper.likeRight(Brand::getFirstLetter, entity.getFirstLetter());
        }
        if (!StringUtils.isEmpty(entity.getFactoryStatus())) {
            wrapper.likeRight(Brand::getFactoryStatus, entity.getFactoryStatus());
        }
        if (!StringUtils.isEmpty(entity.getShowStatus())) {
            wrapper.likeRight(Brand::getShowStatus, entity.getShowStatus());
        }
        wrapper.orderByDesc(BaseEntity::getCreateTime);
    }

}
